package com.wnxy.carl.commons;


import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class BeanUtilsExt extends BeanUtils {
    //BeanUtils.copyProperties无法满足list集合赋值，而封装的工具
    public static <T> List<T> copyPropertiesList(Class<T> type, List<?> lists) {
        List<T> dtos = new ArrayList<>();
        for(Object obj : lists) {
            T t = null;
            try {
                t = type.getDeclaredConstructor().newInstance();
            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
                e.printStackTrace();
            }
            BeanUtils.copyProperties(obj, t);
            dtos.add(t);
        }
        return dtos;
    }
}
